package com.ruoyi.project.mobile.news;

import com.ruoyi.common.utils.R;
import com.ruoyi.common.utils.RFactory;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.project.system.activity.domain.Activity;
import com.ruoyi.project.system.activity.service.IActivityService;
import com.ruoyi.project.system.activitytype.domain.ActivityType;
import com.ruoyi.project.system.activitytype.service.IActivityTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 新闻接口
 *
 * @autor LCL
 * @date - 2020/8/25
 */
@RestController
@RequestMapping("/api/news")
public class ApiNewsController extends BaseController {

    @Autowired
    private IActivityTypeService activityTypeService;
    @Autowired
    private IActivityService activityService;

    /**
     *查询新闻分类
     * @param uid
     * @return
     */
    @GetMapping("/type")
    public R newsType(@RequestParam String uid) {
        ActivityType activityType = new ActivityType();
//        activityType.setStatus(0);
        return RFactory.generateR(this.activityTypeService.selectATList(activityType));
    }

    /**
     * 查询分类下的新闻列表
     * @param typeId 新闻分类ID
     * @return
     */
    @GetMapping("/newslist")
    public R typeNewsList(@RequestParam String typeId) {
        startPage();
        Activity activity = new Activity();
        return RFactory.generateR(getDataTable(this.activityService.selectActivityList(activity)));
    }

    /**
     * 根据ID查询新闻
     * @param id 新闻ID
     * @return
     */
    @GetMapping("/details")
    public R detailsById(@RequestParam String id) {
        return RFactory.generateR(this.activityService.selectActivityById(id));
    }

    /**
     * 首页查询活动咨询
     * @param uid
     * @return
     */
    @GetMapping("/consultation")
    public R consultation(@RequestParam String uid) {
        Activity activity = new Activity();
        activity.setIsShow(1);
        return RFactory.generateR(this.activityService.selectActivityList(activity));
    }

}
